<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <form action="http://localhost:8080/mvc/hello">
      <input type="text" name="n" />
      <button>提交</button>
    </form>
    <a href="http://localhost:8080/mvc/hello">跳转</a>

    <!-- 发送请求 -->
    <button onclick="send()">send</button>

    <script>
      function send() {
        // 1.创建一个XMLHttpRequest对象
        var xhr = new XMLHttpRequest();
        // 2.设置请求方式和请求地址
        xhr.open("post", "http://localhost:8080/mvc/rbody");
        // 3.发送请求
        xhr.send("id=1&name=zs");

        // 4.监听请求状态
        xhr.onreadystatechange = function () {
          console.log(xhr.readyState, xhr.status);
          if (xhr.readyState == 4 && xhr.status == 200) {
            console.log(xhr.responseText);
          }
        };

        xhr.onerror = function (e) {
          console.log("请求失败", e);
        };
      }
    </script>
  </body>
</html>
